package com.dg11185.nearshop.view.adapter;

import java.util.List;

import com.android.nearshop.R;
import com.dg11185.nearshop.net.entity.Address;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AddressAdapter extends BaseAdapter{

    private List<Address> addresses = null;
    
    private LayoutInflater inflater = null;
    
    public AddressAdapter(Context context){
        inflater = LayoutInflater.from(context);    
    }
    
    public void setAddresses(List<Address> addresses) {
        this.addresses = addresses;
    }
    
    @Override
    public int getCount() {
        if(addresses == null){
            return 0;
        }else{
            return addresses.size();
        }
    }

    @Override
    public Object getItem(int position) {
        return addresses.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = inflater.inflate(R.layout.adapter_address, parent, false);
        TextView name = (TextView)convertView.findViewById(R.id.address_name);
        TextView isDefault = (TextView) convertView.findViewById(R.id.default_address);
        TextView address = (TextView)convertView.findViewById(R.id.address_detail);
        TextView post = (TextView)convertView.findViewById(R.id.address_post);
        
        Address entity = addresses.get(position);
        name.setText(entity.name + "      " + entity.phone);
        address.setText(entity.province + "  " + entity.city + "   " + entity.address);
        post.setText(entity.postCode);
        return convertView;
    }

}
